package com.xxbb.chapter_10.login_frame;

import javax.swing.*;


import com.xxbb.chapter_10.base_frame.BaseJFrame;
import com.xxbb.chapter_10.base_panel.BaseJPanel;
import com.xxbb.chapter_10.main_frame.MainFrameTest;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class LoginFrameTest extends BaseJFrame {
    private LoginEventTest event = new LoginEventTest();
    private static BaseJFrame frame = null;

    public LoginFrameTest() {

        //创建窗口
        frame = new BaseJFrame(400, 350, "登录中心")
                .setJPanel(getJPanel())//添加组件
                .setCenterWindow()
                .setResizableWindow(false)
                .showWindow();
    }

    public JPanel getJPanel() {
        //组件
        JLabel titleLabel = new JLabel("登录中心");
        JLabel accountLabel = new JLabel("账号：");
        JTextField accountField = new JTextField(15);
        JLabel passwordLabel = new JLabel("密码：");
        JPasswordField passwordField = new JPasswordField(15);
        JButton jButtonLogin = new JButton("立即登录");
        jButtonLogin.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (event.login(accountField.getText(), passwordField.getText())) {
                    frame.disposeWindow();//隐藏当前窗口
                    MainFrameTest mainFrameTest = new MainFrameTest();

                }

            }
        });
        JButton jButtonRegister = new JButton("注册");

        //行面板
        BaseJPanel jPanelRow0 = new BaseJPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
        BaseJPanel jPanelRow1 = new BaseJPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
        BaseJPanel jPanelRow2 = new BaseJPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
        BaseJPanel jPanelRow3 = new BaseJPanel(new FlowLayout(FlowLayout.RIGHT, 10, 20));

        //添加组件到行面板中
        jPanelRow0.addComponents(titleLabel);
        jPanelRow1.addComponents(accountLabel, accountField);
        jPanelRow2.addComponents(passwordLabel, passwordField);
        jPanelRow3.addComponents(jButtonLogin, jButtonRegister);
        //垂直容器
        Box verticalBox = Box.createVerticalBox();
        verticalBox.add(jPanelRow0);
        verticalBox.add(jPanelRow1);
        verticalBox.add(jPanelRow2);
        verticalBox.add(jPanelRow3);
        //创建总面板
        BaseJPanel jPanel = new BaseJPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
        //添加到总面板中
        jPanel.addComponents(verticalBox);
        return jPanel;
    }
}
